﻿package com.xeem.henkel.pac
{
	import com.adobe.images.*;
	import com.greensock.*;
	import com.greensock.easing.*;
	import com.xeem.core.utils.*;
	import com.xeem.henkel.common.*;
	
	import flash.display.*;
	import flash.events.*;
	import flash.geom.*;
	import flash.net.FileReference;
	import flash.printing.*;
	import flash.text.*;
	
	import org.alivepdf.display.Display;
	import org.alivepdf.layout.Mode;
	import org.alivepdf.layout.Orientation;
	import org.alivepdf.layout.Position;
	import org.alivepdf.layout.Resize;
	import org.alivepdf.layout.Unit;
	import org.alivepdf.pdf.PDF;
	import org.alivepdf.saving.Method;
	
	public class Main extends MovieClip
	{
	
		private var styler:NumberFormat=new NumberFormat();
		
		public function Main()
		{
			init();	
			trace("Hello");
		}
		
		private function init(){
			
			v1.text="";
			v2.text="";
			v3.text="";
			v4.text="";
			v5.text="";
			v6.text="";
			v7.text="";
			v8.text="";
			v9.text="";
			v10.text="";
			v11.text="";
			v12.text="";
			v13.text="";
			v14.text="";
			v15.text="";
			v16.text="";
			
			f1.text="";
			f2.text="";
			f3.text="";
			f4.text="";
			f5.text="";
			f6.text="";
			f7.text="";
			f8.text="";
			
			t1.text="";
			t2.text="";
			
			pp34.addEventListener(MouseEvent.CLICK,onRadioClick);				
			pp35.addEventListener(MouseEvent.CLICK,onRadioClick);
			
			//语言
			c1.addItem({data:"en",label:"English"});
			var tf:TextFormat = new TextFormat();
			tf.size = 9;
			tf.bold=true;
			tf.font = "Arial";
			tf.color=0x008CD6;
			c1.textField.setStyle("textFormat", tf);
			c1.dropdown.setRendererStyle("textFormat", tf);

			//货币
			c2.addItem({data:"$",label:"$"});
			c2.textField.setStyle("textFormat", tf);
			c2.dropdown.setRendererStyle("textFormat", tf);
			
			//
			var tf1:TextFormat = new TextFormat();
			tf1.size = 12;
			tf1.bold=true;
			tf1.font = "Arial";
			tf1.color=0x008CD6;
			tf1.align="center";
			
			c3.setStyle("textFormat", tf1);
			//c3.restrict="0-9";
			c4.setStyle("textFormat", tf1);
			//c4.restrict="0-9";
			
			p5.setStyle("textFormat", tf1);
			p5.restrict="0-9";
			p5.addEventListener(FocusEvent.FOCUS_OUT,onFormatData);   
			p5.addEventListener(FocusEvent.FOCUS_IN,onChangeData);  
			p6.setStyle("textFormat", tf1);
			p6.restrict="0-9";
			p6.addEventListener(FocusEvent.FOCUS_OUT,onFormatData);
			p6.addEventListener(FocusEvent.FOCUS_IN,onChangeData); 
			p7.text="36";			
			p7.setStyle("textFormat", tf1);		
			p7.restrict="0-9";
			p7.addEventListener(FocusEvent.FOCUS_OUT,onFormatData);   
			p7.addEventListener(FocusEvent.FOCUS_IN,onChangeData); 
			p8.text="50";
			p8.setStyle("textFormat", tf1);
			p8.restrict="0-9";
			p8.addEventListener(FocusEvent.FOCUS_OUT,onFormatData);
			p8.addEventListener(FocusEvent.FOCUS_IN,onChangeData); 
			p9.text="100";
			p9.setStyle("textFormat", tf1);
			p9.restrict="0-9";
			p9.addEventListener(FocusEvent.FOCUS_OUT,onFormatData);   
			p9.addEventListener(FocusEvent.FOCUS_IN,onChangeData); 
			p10.text=styler.format(1000,new Locale("en","US"));
			p10.setStyle("textFormat", tf1);
			p10.restrict="0-9";
			p10.addEventListener(FocusEvent.FOCUS_OUT,onFormatData);  
			p10.addEventListener(FocusEvent.FOCUS_IN,onChangeData); 
			p11.text="600";
			p11.setStyle("textFormat", tf1);
			p11.restrict="0-9";
			p11.addEventListener(FocusEvent.FOCUS_OUT,onFormatData);   
			p11.addEventListener(FocusEvent.FOCUS_IN,onChangeData); 
			p12.text=styler.format(1400,new Locale("en","US"));
			p12.setStyle("textFormat", tf1);
			p12.restrict="0-9";
			p12.addEventListener(FocusEvent.FOCUS_OUT,onFormatData);   
			p12.addEventListener(FocusEvent.FOCUS_IN,onChangeData); 
			//Bar 组件  start
			var tx:Number=176.8;
			var d1:DataModel=new DataModel;
			d1.rangeData=10;
			d1.precision=1;
			d1.unit="$/kg";
			d1.minData=0;
			d1.dataDef=0;
			
			p1=new BarComponent(this,134);
			p1.data=d1;
			p1.draw();
			//p1.x=188;
			//p1.y=120;
			p1.x=tx;
			p1.y=116.7;
			p1.addEventListener(Event.CHANGE,onChange);   
			
			var d2:DataModel=new DataModel;
			d2.rangeData=10;
			d2.precision=1;
			d2.unit="$/kg";
			d2.minData=0;
			d2.dataDef=0;
			
			p2=new BarComponent(this,134);
			p2.data=d1;
			p2.draw();
			//p2.x=188;
			//p2.y=172;
			p2.x=tx;
			p2.y=163.75;
			p2.addEventListener(Event.CHANGE,onChange);  
			
			var d3:DataModel=new DataModel;
			d3.rangeData=2000;
			d3.precision=0;
			d3.unit="kg";
			d3.minData=0;
			d3.dataDef=0;
			
			p3=new BarComponent(this,134,10,50);
			p3.data=d3;
			p3.draw();
			//p3.x=188;
			//p3.y=262;
			p3.x=tx;
			p3.y=242;
			p3.addEventListener(Event.CHANGE,onChange);  
			
			var d4:DataModel=new DataModel;
			d4.rangeData=2000;
			d4.precision=0;
			d4.unit="kg";
			d4.minData=0;
			d4.dataDef=0;
			
			p4=new BarComponent(this,134,10,50);
			p4.data=d4;
			p4.draw();
			//p4.x=188;
			//p4.y=313;
			p4.x=tx;
			p4.y=289;
			p4.addEventListener(Event.CHANGE,onChange);  
			
			tx=15.7;
			var d25:DataModel=new DataModel;
			d25.rangeData=10;
			d25.precision=1;
			d25.unit="kw/h";
			d25.minData=0;
			d25.dataDef=5.3;
			
			p25=new BarComponent(this,140,10);
			p25.data=d25;
			p25.draw();
			//p25.x=8;
			//p25.y=420;
			p25.x=tx;
			p25.y=385.3;
			p25.addEventListener(Event.CHANGE,onChange);
			
			var d26:DataModel=new DataModel;
			d26.rangeData=10;
			d26.precision=1;
			d26.unit="kw/h";
			d26.minData=0;
			d26.dataDef=0;
			
			p26=new BarComponent(this,140,10);
			p26.data=d26;
			p26.draw();
			//p26.x=178;
			//p26.y=420;
			p26.x=167.85;
			p26.y=385.3;
			p26.addEventListener(Event.CHANGE,onChange); 
			
			//Monthly running time
			var d27:DataModel=new DataModel;
			d27.rangeData=800;
			d27.precision=0;
			d27.unit="hr";
			d27.minData=0;
			d27.dataDef=0;
			
			p27=new BarComponent(this,295,10,10);
			p27.data=d27;
			p27.draw();
			p27.x=tx;
			//p27.y=477;
			p27.y=436.75;
			p27.addEventListener(Event.CHANGE,onChange);  
			
			
			var d28:DataModel=new DataModel;
			d28.rangeData=1;
			d28.precision=2;
			d28.unit="$/kw";
			d28.minData=0;
			d28.dataDef=0;
			
			p28=new BarComponent(this,295,10);
			p28.data=d28;
			p28.draw();
			p28.x=tx;
			//p28.y=530;
			p28.y=483.75;
			p28.addEventListener(Event.CHANGE,onChange);  
			
			
			
			//Bar 组件  end
			
			//circle 组件  start
			var d13:DataModel=new DataModel;
			d13.rangeData=10;
			d13.precision=0;
			d13.unit="";
			d13.minData=0;
			d13.dataDef=0;
			
			tx=453.75;
			p13=new CircleComponent(this);
			p13.data=d13;
			p13.draw();			
			p13.x=tx;
			p13.y=121;
			p13.addEventListener(Event.CHANGE,onChange);  
			
			var d14:DataModel=new DataModel;
			d14.rangeData=10;
			d14.precision=0;
			d14.unit="";
			d14.minData=0;
			d14.dataDef=0;
			
			p14=new CircleComponent(this);
			p14.data=d14;
			p14.draw();			
			p14.x=tx;
			p14.y=165;
			p14.addEventListener(Event.CHANGE,onChange);  
			
			var d15:DataModel=new DataModel;
			d15.rangeData=10;
			d15.precision=0;
			d15.unit="";
			d15.minData=0;
			d15.dataDef=0;
			
			p15=new CircleComponent(this);
			p15.data=d15;
			p15.draw();			
			p15.x=tx;
			p15.y=210;
			p15.addEventListener(Event.CHANGE,onChange);  
			
			var d16:DataModel=new DataModel;
			d16.rangeData=5;
			d16.precision=1;
			d16.unit="";
			d16.minData=0;
			d16.dataDef=0;
			
			p16=new CircleComponent(this,1,0.5);
			p16.data=d16;
			p16.draw();			
			p16.x=tx;
			p16.y=255;
			p16.addEventListener(Event.CHANGE,onChange);  
		
			var d17:DataModel=new DataModel;
			d17.rangeData=1;
			d17.precision=1;
			d17.unit="";
			d17.minData=0;
			d17.dataDef=1;
			
			p17=new CircleComponent(this,2);
			p17.data=d17;
			p17.draw();			
			p17.x=tx;
			p17.y=300;
			p17.addEventListener(Event.CHANGE,onChange);  
			
			var d18:DataModel=new DataModel;
			d18.rangeData=1;
			d18.precision=1;
			d18.unit="";
			d18.minData=0;
			d18.dataDef=0;
			
			p18=new CircleComponent(this,2);
			p18.data=d18;
			p18.draw();			
			p18.x=tx;
			p18.y=340;
			p18.addEventListener(Event.CHANGE,onChange);  
			
			tx=515;
			var d19:DataModel=new DataModel;
			d19.rangeData=10;
			d19.precision=0;
			d19.unit="";
			d19.minData=0;
			d19.dataDef=0;
			
			p19=new CircleComponent(this);
			p19.data=d19;
			p19.draw();			
			p19.x=tx;
			p19.y=121;
			p19.addEventListener(Event.CHANGE,onChange);  
			
			var d20:DataModel=new DataModel;
			d20.rangeData=10;
			d20.precision=0;
			d20.unit="";
			d20.minData=0;
			d20.dataDef=0;
			
			p20=new CircleComponent(this);
			p20.data=d20;
			p20.draw();			
			p20.x=tx;
			p20.y=165;
			p20.addEventListener(Event.CHANGE,onChange);  
			
			var d21:DataModel=new DataModel;
			d21.rangeData=10;
			d21.precision=0;
			d21.unit="";
			d21.minData=0;
			d21.dataDef=0;
			
			p21=new CircleComponent(this);
			p21.data=d21;
			p21.draw();			
			p21.x=tx;
			p21.y=210;
			p21.addEventListener(Event.CHANGE,onChange); 
			
			var d22:DataModel=new DataModel;
			d22.rangeData=5;
			d22.precision=1;
			d22.unit="";
			d22.minData=0;
			d22.dataDef=0;
			
			p22=new CircleComponent(this,1,0.5);
			p22.data=d22;
			p22.draw();			
			p22.x=tx;
			p22.y=255;
			p22.addEventListener(Event.CHANGE,onChange);  
			
			var d23:DataModel=new DataModel;
			d23.rangeData=1;
			d23.precision=1;
			d23.unit="";
			d23.minData=0;
			d23.dataDef=1;
			
			p23=new CircleComponent(this,2);
			p23.data=d23;
			p23.draw();			
			p23.x=tx;
			p23.y=300;
			p23.addEventListener(Event.CHANGE,onChange);  
			
			var d24:DataModel=new DataModel;
			d24.rangeData=1;
			d24.precision=1;
			d24.unit="";
			d24.minData=0;
			d24.dataDef=0;
			
			p24=new CircleComponent(this,2);
			p24.data=d24;
			p24.draw();			
			p24.x=tx;
			p24.y=340;
			p24.addEventListener(Event.CHANGE,onChange);  
			
			//Machine hour cost
			var d29:DataModel=new DataModel;
			d29.rangeData=1500;
			d29.precision=0;
			d29.unit="$/hr";
			d29.minData=0;
			d29.dataDef=0;
			
			p29=new BarComponent(this,219,10,10);
			p29.data=d29;
			p29.draw();
			//p29.x=372;
			//p29.y=451;
			p29.x=337.95;
			p29.y=416.6;
			p29.addEventListener(Event.CHANGE,onChange);  
			
			tx=470;
			
			var d30:DataModel=new DataModel;
			d30.rangeData=20;
			d30.precision=0;
			d30.unit="";
			d30.minData=0;
			d30.dataDef=0;
			
			
			p30=new CircleComponent(this,2,2);
			p30.data=d30;
			p30.draw();			
			//p30.x=368;
			p30.x=338;
			p30.y=tx;
			p30.addEventListener(Event.CHANGE,onChange);  
			
			var d31:DataModel=new DataModel;
			d31.rangeData=10;
			d31.precision=0;
			d31.unit="";
			d31.minData=0;
			d31.dataDef=0;
			
			p31=new CircleComponent(this,2,1);
			p31.data=d31;
			p31.draw();			
			//p31.x=430;
			p31.x=395;
			p31.y=tx;
			p31.addEventListener(Event.CHANGE,onChange);  
			
			var d32:DataModel=new DataModel;
			d32.rangeData=20;
			d32.precision=0;
			d32.unit="";
			d32.minData=0;
			d32.dataDef=0;
			
			p32=new CircleComponent(this,2,2);
			p32.data=d32;
			p32.draw();			
			//p32.x=505;
			p32.x=465;
			p32.y=tx;
			p32.addEventListener(Event.CHANGE,onChange);  
			
			var d33:DataModel=new DataModel;
			d33.rangeData=10;
			d33.precision=0;
			d33.unit="";
			d33.minData=0;
			d33.dataDef=0;
			
			p33=new CircleComponent(this,2,1);
			p33.data=d33;
			p33.draw();			
			//p33.x=570;
			p33.x=520;
			p33.y=tx;
			p33.addEventListener(Event.CHANGE,onChange);  
			
			//circle 组件  end
			
			//Clock 组件  start
			
			var dt1:DataModel=new DataModel;
			dt1.minData=0;
			dt1.precision=0;
			dt1.rangeData=100000;
			dt1.unit="";
		
			tc1=new Clock();
			tc1.data=dt1;
			//tc1.x=375;
			//tc1.y=640;
			tc1.x=340;
			tc1.y=578;
			
			addChild(tc1);
			
			var dt2:DataModel=new DataModel;
			dt2.minData=0;
			dt2.precision=0;
			dt2.rangeData=100000;
			dt2.unit="";
			
			tc2=new Clock();
			tc2.data=dt2;
			//tc2.x=510;
			//tc2.y=640;
			
			tc2.x=455;
			tc2.y=578;
			addChild(tc2);
			
			
			//Clock 组件  end
			
		
			h1.data="machine";
			h1.addEventListener(MouseEvent.CLICK,openHelp);
			h2.data="energy";
			h2.addEventListener(MouseEvent.CLICK,openHelp);
			h3.data="consume";
			h3.addEventListener(MouseEvent.CLICK,openHelp);
			h4=new btnHelp();
		    h4.x=528.95;
			h4.y=392.4;
			h4.data="downtime";
			h4.addEventListener(MouseEvent.CLICK,openHelp);
			tp1.addEventListener(MouseEvent.CLICK,onSave); 
			tp2.addEventListener(MouseEvent.CLICK,onPrint);  
			addChild(h4);	
			
			var evt:Event=new Event(Event.CHANGE);   
			onChange(evt);
			popUp.visible=false;
			addChild(popUp);
		
		}
		
		private function onRadioClick(e:MouseEvent):void{
			f34=e.target.value;
			var evt:Event=new Event(Event.CHANGE);   
			onChange(evt);
		}
		
		private function onChange(e:Event):void{
			
			var tf1:TextFormat = new TextFormat();
			tf1.size = 9;
			tf1.bold=true;
			tf1.font = "Arial";
			tf1.color=0xffffff;
			tf1.align="center";
			
			var tf2:TextFormat = new TextFormat();
			tf2.size = 9;
			tf2.bold=true;
			tf2.font = "Arial";
			tf2.color=0x008CD6;
			tf2.align="center";
			
			//Price
			//v1.text=round(p1.value,1).toString()+(round(p1.value,1)==int(p1.value)?".0":"");
			v1.text=round(p1.value,1).toString();
			v1.setStyle("textFormat", tf1);			
			//v2.text=round(p2.value,1).toString()+(round(p2.value,1)==int(p2.value)?".0":"");
			v2.text=round(p2.value,1).toString();
			v2.setStyle("textFormat", tf1);
			
			//Annual glue consumption
			v3.text=styler.format(round(p3.value*12,0),new Locale("en","US")).toString();
			v3.setStyle("textFormat", tf1);
			v4.text=styler.format(round(p4.value*12,0),new Locale("en","US")).toString();
			v4.setStyle("textFormat", tf1);
			f2.text=styler.format(round(p3.value*12-p4.value*12,0),new Locale("en","US")).toString();
			f2.setStyle("textFormat", tf1);
			
			
			//Adhesive Cost
			v5.text=styler.format(round(round(p1.value,1)*p3.value*12,0),new Locale("en","US")).toString();
			v5.setStyle("textFormat", tf2);	
			v6.text=styler.format(round(round(p2.value,1)*p4.value*12,0),new Locale("en","US")).toString();
			v6.setStyle("textFormat", tf2);
			f3.text=styler.format(round(Number(v5.text.split(",").join(""))-Number(v6.text.split(",").join("")),0),new Locale("en","US")).toString();
			f3.setStyle("textFormat", tf2);
			
			//Machine & Service Cost
			v7.text=styler.format(round(Number(p5.text.split(",").join(""))/5+Number(p6.text.split(",").join("")),0),new Locale("en","US")).toString();
			v7.setStyle("textFormat", tf2);	
			v8.text="0";
			v8.setStyle("textFormat", tf2);
			f4.text=styler.format(round(Number(v7.text.split(",").join(""))-Number(v8.text.split(",").join("")),0),new Locale("en","US")).toString();
			f4.setStyle("textFormat", tf2);
			
			//Maintenance Cost
			v9.text=styler.format(round(Number(p7.text.split(",").join(""))*p13.value+Number(p8.text.split(",").join(""))*p14.value+Number(p9.text.split(",").join(""))*p15.value+Number(p10.text.split(",").join(""))*p16.value+Number(p11.text.split(",").join(""))*p17.value+Number(p12.text.split(",").join(""))*p18.value,0),new Locale("en","US")).toString();
			v9.setStyle("textFormat", tf2);	
			
		    //if (f34=="T") 
			//	v10.text="0";
			//else
				v10.text=styler.format(round(Number(p7.text.split(",").join(""))*p19.value+Number(p8.text.split(",").join(""))*p20.value+Number(p9.text.split(",").join(""))*p21.value+Number(p10.text.split(",").join(""))*p22.value+Number(p11.text.split(",").join(""))*p23.value+Number(p12.text.split(",").join(""))*p24.value,0),new Locale("en","US")).toString();
			v10.setStyle("textFormat", tf2);
			f5.text=styler.format(round(Number(v9.text.split(",").join(""))-Number(v10.text.split(",").join("")),0),new Locale("en","US")).toString();
			f5.setStyle("textFormat", tf2);
			
			//Downtime Cost
			v11.text=styler.format(round(p29.value*(p30.value+p32.value)*12,0),new Locale("en","US")).toString();
			v11.setStyle("textFormat", tf2);	
			v12.text=styler.format(round(p29.value*(p31.value+p33.value)*12,0),new Locale("en","US")).toString();
			v12.setStyle("textFormat", tf2);
			f6.text=styler.format(round(Number(v11.text.split(",").join(""))-Number(v12.text.split(",").join("")),0),new Locale("en","US")).toString();
			f6.setStyle("textFormat", tf2);
			
			//Enery Cost
			v13.text=styler.format(round(p25.value*p27.value*p28.value*12,0),new Locale("en","US")).toString();
			v13.setStyle("textFormat", tf2);	
			v14.text=styler.format(round(p26.value*p27.value*p28.value*12,0),new Locale("en","US")).toString();
			v14.setStyle("textFormat", tf2);
			f7.text=styler.format(round(Number(v13.text.split(",").join(""))-Number(v14.text.split(",").join("")),0),new Locale("en","US")).toString();
			f7.setStyle("textFormat", tf2);
			
			//Total Cost
			v15.text=styler.format(round(Number(v5.text.split(",").join(""))+Number(v7.text.split(",").join(""))+Number(v9.text.split(",").join(""))+Number(v11.text.split(",").join(""))+Number(v13.text.split(",").join("")),0),new Locale("en","US")).toString();
			v15.setStyle("textFormat", tf1);	
			v16.text=styler.format(round(Number(v6.text.split(",").join(""))+Number(v8.text.split(",").join(""))+Number(v10.text.split(",").join(""))+Number(v12.text.split(",").join(""))+Number(v14.text.split(",").join("")),0),new Locale("en","US")).toString();
			v16.setStyle("textFormat", tf1);	
			f8.text=styler.format(round(Number(v15.text.split(",").join(""))-Number(v16.text.split(",").join("")),0),new Locale("en","US")).toString();
			f8.setStyle("textFormat", tf1);
			
			//Clock1		
			var tt1:Number=Number(p3.value*12-p4.value*12);	
			if (tt1<0) tt1=0;
			if (tt1>100000) tt1=100000;
			t1.text=styler.format(tt1,new Locale("en","US"));
			t1.setStyle("textFormat", tf2);
			tc1.drawData(tt1);
			
			//Clock2
			var tt2:Number=Number(f8.text.split(",").join(""));
			if (tt2<0) tt2=0;
			if (tt2>100000) tt2=100000;
			t2.text=styler.format(tt2,new Locale("en","US"));
			t2.setStyle("textFormat", tf2);
			tc2.drawData(tt2);						
		}
		
		private function onFormatData(e:FocusEvent):void{
			if (isNaN(e.currentTarget.text.split(",").join(""))) e.currentTarget.text="0";
			e.currentTarget.text=styler.format(Number(e.currentTarget.text.split(",").join("")),new Locale("en","US"));
			onChange(e);
		}
		
		private function onChangeData(e:FocusEvent):void{
			e.currentTarget.text=e.currentTarget.text.split(",").join("");
		}
		
		private function round(x:Number,p:int):Number{
			if (p==0){
				return Math.round(x);
			}else{
				return Math.round(x*Math.pow(10,p))/Math.pow(10,p);
			}
		}
		
		private function onPrint(e:MouseEvent):void{
			var printJob:PrintJob=new PrintJob(); 
		    var printArea:Rectangle; 
			  if (!printJob.start()) 
			      return; 
				this.width=printJob.pageWidth; 
				this.scaleY=this.scaleX; 
				printJob.addPage(this, printArea);
				printArea=new Rectangle(0, 0, printJob.pageWidth, printJob.pageHeight); 
				printJob.send();  
				/* Delete job from memory */ 
				printJob=null; 			 
			  
		}
		
		private function onSave(e:MouseEvent):void{
			var bit:BitmapData = new BitmapData(this.width,this.height); 
			bit.draw(this); 
			var jpg:JPGEncoder = new JPGEncoder(100); 
			var file:FileReference = new FileReference(); 	
			//file.save(jpg.encode(bit),"henkel"+(new Date().fullYear*10000+(new Date().month+1)*100+new Date().date).toString()+".jpg");		
			var myPDF:PDF = new PDF( Orientation.PORTRAIT, Unit.POINT);  
			myPDF.setDisplayMode ( Display.REAL );  
			myPDF.addPage();
			myPDF.addImage( this, new Resize (Mode.FIT_TO_PAGE, Position.CENTERED ) );
			file.save(myPDF.save(Method.LOCAL ),"henkel"+(new Date().fullYear*10000+(new Date().month+1)*100+new Date().date).toString()+".pdf");		
		}
		
		private function openHelp(e:MouseEvent):void{
			var s:SimpleButton=e.currentTarget as SimpleButton;
			popUp.gotoAndStop(s.data);	
			if (s.data=="machine")
				popUp.c1.addEventListener(MouseEvent.MOUSE_DOWN,onbegin);
			if (s.data=="energy")
				popUp.c2.addEventListener(MouseEvent.MOUSE_DOWN,onbegin);
			if (s.data=="downtime")
				popUp.c3.addEventListener(MouseEvent.MOUSE_DOWN,onbegin);
			if (s.data=="consume")
				popUp.c4.addEventListener(MouseEvent.MOUSE_DOWN,onbegin);
			
			trace(this.width);
			trace(popUp.width);
			if (s.data=="consume"){
				popUp.x=(580-popUp.width)/2-20;
				popUp.y=80;
			}else{
				popUp.x=(580-popUp.width)/2;
				popUp.y=(740-popUp.height)/2;
			}
			popUp.scaleX=popUp.scaleY=0;
			popUp.alpha=0.2;
			popUp.visible=true;
			if (s.data=="consume")
				TweenLite.to(popUp,0.6,{delay:0.1,alpha:1,scaleX:1,scaleY:1});
			else
				TweenLite.to(popUp,0.6,{delay:0.1,alpha:1,scaleX:1,scaleY:1});	
		}
		
		
		private function onbegin(e:Event):void {
			TweenLite.to(popUp,1,{delay:0.5,alpha:0});
			popUp.visible=false;			
		}
	}
}